/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.ldap.LdapDIT;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_43147
/*     */   extends UpgradeOp
/*     */ {
/*     */   void doUpgrade()
/*     */     throws ServiceException
/*     */   {
/*  39 */     Set<String> galSyncAcctIds = getAllGalSyncAcctIds();
/*     */     
/*  41 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  43 */       upgradeGalSyncAcct(zlc, galSyncAcctIds);
/*     */     } finally {
/*  45 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */   private static class Bug43147Visitor extends SearchLdapOptions.SearchLdapVisitor
/*     */   {
/*     */     private UpgradeOp upgradeOp;
/*     */     private Set<String> galSyncAcctIds;
/*     */     
/*     */     Bug43147Visitor(UpgradeOp upgradeOp, Set<String> galSyncAcctIds) {
/*  55 */       this.upgradeOp = upgradeOp;
/*  56 */       this.galSyncAcctIds = galSyncAcctIds;
/*     */     }
/*     */     
/*     */     public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs)
/*     */     {
/*  61 */       this.upgradeOp.printer.println("Domain " + attrs.get("zimbraDomainName"));
/*     */       
/*  63 */       Object values = attrs.get("zimbraGalAccountId");
/*  64 */       if ((values instanceof String)) {
/*  65 */         this.upgradeOp.printer.println(" GAL sync account " + (String)values);
/*  66 */         this.galSyncAcctIds.add((String)values);
/*  67 */       } else if ((values instanceof String[])) {
/*  68 */         for (String value : (String[])values) {
/*  69 */           this.upgradeOp.printer.println(" GAL sync account " + value);
/*  70 */           this.galSyncAcctIds.add(value);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private Set<String> getAllGalSyncAcctIds() throws ServiceException {
/*  77 */     Set<String> galSyncAcctIds = new HashSet();
/*     */     
/*  79 */     Bug43147Visitor visitor = new Bug43147Visitor(this, galSyncAcctIds);
/*     */     
/*  81 */     String query = "(&(objectClass=zimbraDomain)(zimbraGalAccountId=*))";
/*  82 */     String[] bases = this.prov.getDIT().getSearchBases(16);
/*  83 */     String[] attrs = { "zimbraDomainName", "zimbraGalAccountId" };
/*     */     
/*     */ 
/*  86 */     for (String base : bases) {
/*  87 */       this.prov.searchLdapOnMaster(base, query, attrs, visitor);
/*     */     }
/*     */     
/*  90 */     return galSyncAcctIds;
/*     */   }
/*     */   
/*     */   private void upgradeGalSyncAcct(ZLdapContext zlc, Set<String> galSyncAcctIds) throws ServiceException {
/*  94 */     this.printer.println();
/*  95 */     this.printer.println("Upgrading zimbraContactMaxNumEntries on GAL sync accounts ...");
/*  96 */     this.printer.println();
/*     */     
/*  98 */     HashMap<String, Object> attrs = new HashMap();
/*  99 */     attrs.put("zimbraContactMaxNumEntries", "0");
/*     */     
/*     */ 
/* 102 */     for (String id : galSyncAcctIds) {
/* 103 */       Account acct = this.prov.getAccountById(id);
/* 104 */       if (acct != null)
/*     */       {
/*     */ 
/* 107 */         String curValue = acct.getAttr("zimbraContactMaxNumEntries", false);
/*     */         
/* 109 */         if (curValue == null) {
/*     */           try {
/* 111 */             this.printer.println("Account: " + acct.getId() + "(" + acct.getName() + ") - " + "modifying zimbraContactMaxNumEntries to 0");
/* 112 */             modifyAttrs(zlc, acct, attrs);
/*     */           } catch (ServiceException e) {
/* 114 */             this.printer.println("Caught ServiceException while modifying GAL sync account entry " + acct.getName());
/* 115 */             this.printer.printStackTrace(e);
/*     */           }
/*     */         } else
/* 118 */           this.printer.println("Account: " + acct.getId() + "(" + acct.getName() + ") - " + "already has value " + curValue + ", skipping");
/*     */       } else {
/* 120 */         this.printer.println("Account: " + id + " - no such account");
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_43147.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */